package com.graduation.clientback.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.graduation.clientback.common.R;
import com.graduation.clientback.domain.Work;
import com.graduation.clientback.service.WorkService;
import com.graduation.clientback.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/work")
public class WorkController {

    @Autowired
    private WorkService workService;

    /**
     * 获取学生毕设作品信息
     * @return
     */
    @GetMapping("/detail")
    public R<Work> getWork(){
        Map<String, Object> claims = ThreadLocalUtil.get();
        Integer userId = (Integer) claims.get("id");
        LambdaQueryWrapper<Work> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Work::getStuId, userId);
        return R.success(workService.getOne(queryWrapper));
    }

    /**
     * 查询导师对应的毕设列表
     * @param tchId
     * @return
     */
    @GetMapping("/list")
    public R<List<Work>> list(){
        Map<String, Object> claims = ThreadLocalUtil.get();
        Integer tchId = (Integer) claims.get("id");
        LambdaQueryWrapper<Work> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Work::getTchId, tchId);
        return R.success(workService.list(queryWrapper));
    }
}
